package com.example.wanxiang_app;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.baidu.mobstat.StatService;

import java.util.Map;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
    private static final String CHANNEL = "app.channel.notifaction";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        String action = intent.getAction();


    }

    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);

        new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
                .setMethodCallHandler(
                        (call, result) -> {
                            if (call.method.contentEquals("notifactionJson")) {
                                StatService.setAppKey("70326b5fc8");
                                StatService.setAppChannel( "Baidu Market");
                                StatService.setAuthorizedState(getActivity(), false);
                                StatService.autoTrace(getActivity());
                            }else if(call.method.contentEquals("getbadge")){
                                Map<String,String> arguments =  (Map<String,String>)call.arguments;
                                String toString = arguments.get("badgenum").toString();
                                String type = arguments.get("badgetype");
                                if(TextUtils.isEmpty(type) || !type.equals("newmsg")){
                                    int toInt = Integer.parseInt(toString);
                                    //设置角标
                                    AppShortCutUtil.setCount(toInt, this);
                                }

                            }else if(call.method.contentEquals("writemsg")){
                                Map<String,String> arguments =  (Map<String,String>)call.arguments;
                                String toString = arguments.get("msg");
                                AppShortCutUtil.writefile(toString,this);
                            }
                        }
                );
    }

}
